$(document).ready(function(){
    $.fn.dataTable.ext.errMode = 'none';
    $('#table_list').on( 'error.dt', function ( e, settings, techNote, message ) {
        $.jBox.error(GLOBAL_DATATBALE_ERROR_302, '错误');
        return false;
    } ).DataTable({
        dom: '<"top">rt<"bottom"flip><"clear">',
        language: {
            "sUrl":'../static/plugins/datatables/language.json'
        },
        "searching": false,
        "processing": true,
        "serverSide": true,
        "scrollY": "550px",
        "scrollCollapse": true,
        "scrollX": true,
        ajax:{
            url:'/sys-log/sms-load-list',
            type:'post',
            data:function(d){
                d.mobile = $('#mobile').val();
                d.sms_status = $('#sms_status').val();
                d.dateval = $('#reservationtime').val();
            },
            error:getError
        },
        aoColumns: [
            { "data": "id", "bSortable": true},
            { "data": "mobile", "bSortable":false },
            { "data": "sms_content", "bSortable":false },
            { "data": "ip", "bSortable":false },
            { "data": "sms_status", "bSortable":false },
            { "data": "fail_content", "bSortable":false },
            { "data": "task_id", "bSortable":false },
            { "data": "create_time", "bSortable":true }
        ],
        columnDefs: [
            {
                "targets": [0],
                "orderable":false,
                "searchable":false
            },
            {
                "targets": [4],
                "orderable":false,
                "searchable":false,
                "render": function(data, type, full) {

                    switch (data){
                        case '0':
                            return '未发送';
                            break;
                        case '1':
                            return '已发送';
                            break;
                        case '2':
                            return '发送失败';
                            break;
                        default :
                            return '';
                    }
                }
            },
        ],
        order: [[ 0, "desc" ]]                      //初始指定排序字段
    });
});


$('#reservationtime').daterangepicker({
    language:  'zh-CN',
    timePicker: true,
    timePickerIncrement: 30,
    format: 'YYYY/MM/DD h:mm A',
    locale: {
        format: 'YYYY-MM-DD HH:mm',
        daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
        monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
    }
});

$('#select_button').click(function(){
    var table = $('#table_list').DataTable();
    table.ajax.reload();

})

function viewInfo(id){
    $.ajax({
        type: "post",
        dataType: "json",
        url:'/sys-log/backend-load-info',
        data: {id:id},
        success: function (data) {
            if(data.code == 200)
            {
                $('#loginfo').val(data.val);//日志内容
                $('#myModal').modal('show');
            }
            else{
                $.jBox.error(data.val, '错误');
            }
        }
    });

}

$('#reset_button').click(function(){
    $('#mobile').val('');
    $('#sms_status').val('');
    $('#reservationtime').val('');
    var table = $('#table_list').DataTable();
    table.ajax.reload();
})


var setting = {
    view: {
        showIcon: false
    },
    data: {
        simpleData: {
            enable: true,
            idKey:"id",
            pIdKey:"pId"
        }
    }
};

var setting_other = {
    view: {
        showIcon: false
    },
    data: {
        simpleData: {
            enable: true,
            idKey:"id",
            pIdKey:"pId"
        }
    }
};